package com.dhcc.controller;

import com.dhcc.entity.User;
import com.dhcc.repository.UserRepository;
import com.dhcc.util.PageTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PageController {

    @Autowired
    private UserRepository userRepository;

    @RequestMapping("pageTest")
    public List<User> pageUser(@RequestParam("curPage") Integer curPage, @RequestParam("pageCount") Integer pageCount) {
        int totalCount = userRepository.getCount();
        PageTool pt = new PageTool(curPage,totalCount,pageCount);
        int stratIndex = pt.getStartIndex();
        int endIndex = pt.getEndIndex();
        System.out.println("startIndex:"+stratIndex+",endIndex:"+endIndex);
        List<User> list = userRepository.getUser(stratIndex,pageCount);
        System.out.println(list);
        return list;
    }
}
